package com.golddaymicromall.activity.storemanager;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.golddaymicromall.activity.R;
import com.golddaymicromall.application.MyApplication;
import com.golddaymicromall.base.BaseActivity;
import com.golddaymicromall.bean.StoreAddInfo;
import com.golddaymicromall.bean.StoreTypeInfo;
import com.golddaymicromall.util.MD5;
import com.golddaymicromall.util.RopUtils;
import com.golddaymicromall.util.SPUtils;
import com.golddaymicromall.util.ServerConfig;
import com.google.common.collect.Maps;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.convert.StringConvert;
import com.lzy.okrx.RxAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import rx.android.schedulers.AndroidSchedulers;

public class StoreAddActivity extends BaseActivity implements View.OnClickListener {

    //控件类
    private LinearLayout mStoreBack;
    private Button mCreateQR;
    private Button mAddBehalf;
    private Spinner mAdd_applyLevel;
    private Spinner mAdd_storeType;
    private EditText mAdd_marketManagerNo;
    private EditText mAdd_marketNo;
    private Spinner mAdd_choiceMarket;
    private RadioButton mRadioMoren;
    private RadioButton mRadioDiy;
    private RadioButton mRadioFirst;
    private RadioButton mRadioSecond;
    private TextView mAdd_ChoiseMarketText;
    private Button mAdd_ChoiseBtn;
    private Button mValidate;
    //参数类
    private String logid;
    List<String> listType = null;
    private String mStoreType;
    List listCustomerMarket = null;
    List<StoreAddInfo> listAddInfo = null;
    List<String> listApplyLevel = null;
    String customerNo = null;
    String applyLevel = "0";
    String region = "1";
    String marketBottom;
    String mDeptFlag;
    String selecttype = "默认";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_store_add);
        region = "1";
        initView();
        attemptApplyLevel();
        attemptGetStoreTypeTask();
        attemptGetCustomerMarket();
        mRadioMoren.setOnClickListener(v -> {
            attemptQueryByCusNoMoRen();
            selecttype = "默认";
            MyApplication.getInstance().attemptRiZhi(SPUtils.get(getApplicationContext(), "Customerno", "").toString(),
                    SPUtils.get(getApplicationContext(), "Customerno", "").toString() + "," + mAdd_marketManagerNo.getText() + "新增店铺，点击默认Radio");
        });
        mRadioDiy.setOnClickListener(v -> {
            attemptQueryByCusNoDIY();
            selecttype = "自选";
            MyApplication.getInstance().attemptRiZhi(SPUtils.get(getApplicationContext(), "Customerno", "").toString(),
                    SPUtils.get(getApplicationContext(), "Customerno", "").toString() + "," + mAdd_marketManagerNo.getText() + "新增店铺，点击自定义Radio");
        });
        mRadioFirst.setOnClickListener(v -> marketBottom = "1");
        mRadioSecond.setOnClickListener(v -> marketBottom = "2");
    }

    public void initView() {
        mStoreBack = (LinearLayout) findViewById(R.id.store_back);
        mCreateQR = (Button) findViewById(R.id.add_btn_createQr);
        mAddBehalf = (Button) findViewById(R.id.add_btn_behalf);
        mValidate = (Button) findViewById(R.id.add_btn_validate);
        mAdd_applyLevel = (Spinner) findViewById(R.id.add_applyLevel);
        mAdd_storeType = (Spinner) findViewById(R.id.add_storeType);
        mAdd_marketManagerNo = (EditText) findViewById(R.id.add_marketManagerNo);
        mAdd_choiceMarket = (Spinner) findViewById(R.id.add_choiceMarket);
        mAdd_marketNo = (EditText) findViewById(R.id.add_marketNo);
        mRadioMoren = (RadioButton) findViewById(R.id.radioMoren);
        mRadioDiy = (RadioButton) findViewById(R.id.radioDIY);
        mAdd_ChoiseMarketText = (TextView) findViewById(R.id.add_choiceMarketText);
        mAdd_ChoiseBtn = (Button) findViewById(R.id.add_choiseBtn);
        mRadioFirst = (RadioButton) findViewById(R.id.firstRadio);
        mRadioSecond = (RadioButton) findViewById(R.id.secondRadio);
        mStoreBack.setOnClickListener(this);
        mCreateQR.setOnClickListener(this);
        mAddBehalf.setOnClickListener(this);
        mValidate.setOnClickListener(this);
        mAdd_ChoiseBtn.setOnClickListener(this);
        mCreateQR.setVisibility(View.GONE);
        mAddBehalf.setVisibility(View.GONE);
        mAdd_marketManagerNo.setText(SPUtils.get(getApplicationContext(), "Customerno", "").toString());
        mDeptFlag = SPUtils.get(getApplicationContext(), "deptFlag", "").toString();
        logid = SPUtils.get(getApplicationContext(), "Id", "").toString();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.add_btn_createQr:
                attemptCreateQr(1);
                MyApplication.getInstance().attemptRiZhi(SPUtils.get(getApplicationContext(), "Customerno", "").toString(),
                        SPUtils.get(getApplicationContext(), "Customerno", "").toString() + "," + mAdd_marketManagerNo.getText() + "新增店铺，生成二维码");
                break;
            case R.id.add_btn_behalf:
                attemptCreateQr(2);
                break;
            case R.id.add_btn_validate:
                attempValidateDiyTask();
                MyApplication.getInstance().attemptRiZhi(SPUtils.get(getApplicationContext(), "Customerno", "").toString(),
                        SPUtils.get(getApplicationContext(), "Customerno", "").toString() + "," + mAdd_marketManagerNo.getText() + "新增店铺，验证信息");
                break;
            case R.id.add_choiseBtn:
                attemptQueryByCusNoMoRen();
                MyApplication.getInstance().attemptRiZhi(SPUtils.get(getApplicationContext(), "Customerno", "").toString(),
                        SPUtils.get(getApplicationContext(), "Customerno", "").toString() + "," + mAdd_marketManagerNo.getText() + "新增店铺，点击确定");
                break;
            case R.id.store_back:
                finish();
                break;
            default:
                break;
        }
    }

    //根据自定的数据生成二维码
    public void attemptCreateQr(int flag) {
        try {
            if ("".equals(mAdd_marketManagerNo.getText().toString().trim())) {
                Toast.makeText(getApplicationContext(), "市场管理人编号不能为空",
                        Toast.LENGTH_LONG).show();
                return;
            }
            if ("".equals(mAdd_marketNo.getText().toString().trim())) {
                Toast.makeText(getApplicationContext(), "市场编号不能为空",
                        Toast.LENGTH_LONG).show();
                return;
            }
            //获取数据
            String managerNo = mAdd_marketManagerNo.getText().toString().trim(); //管理员编号
            String pcustomerno = mAdd_marketNo.getText().toString().trim(); //自定义编号
            //grade  市场级别
            //============华丽的分割线============
            Map<String, Object> form = new HashMap<String, Object>();
            form.put("grade", applyLevel);
            form.put("shop_grade", mStoreType);
            form.put("rcustomerno", managerNo);
            form.put("pcustomerno", pcustomerno);
            form.put("flag", mDeptFlag);
            form.put("selecttype", "A-" + selecttype);
            if (mRadioDiy.isChecked()) {
                if (mRadioFirst.isChecked() || mRadioSecond.isChecked()) {
                    form.put("region", marketBottom);
                } else {
                    Toast.makeText(StoreAddActivity.this, "请选择下面的市场", Toast.LENGTH_SHORT).show();
                }
            } else {
                form.put("region", region);
            }

            MD5 md5 = new MD5();

            String md5str = md5.toMD5("madeinjinying" + applyLevel + mStoreType + managerNo + pcustomerno + region).substring(6, 22).toLowerCase();

            String url = new ServerConfig().QRURL + new ServerConfig().getUrlParamsByMap(form) + "&md5str=" + md5str;
            MyApplication.getInstance().attemptRiZhi(SPUtils.get(getApplicationContext(), "Customerno", "").toString(),
                    SPUtils.get(getApplicationContext(), "Customerno", "").toString() + ",添加店铺，地址：" + url);
            if (flag == 1) {
                Intent intent2qr = new Intent(this, DisplayQrActivity.class);
                intent2qr.putExtra("url", url);
                startActivity(intent2qr);
            } else if (flag == 2) {
                Intent toBehalf = new Intent(this, StoreAddBehalfActivity.class);
                toBehalf.putExtra("url", url);
                startActivity(toBehalf);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //获取申请级别
    public void attemptApplyLevel() {
        Map<String, String> form = Maps.newHashMap();
        form.put("method", "rop.dictionnary.get");
        form.put("appKey", "00001");
        form.put("v", "1.0");
        form.put("format", "json");
        form.put("Parentid", "275");
        String sing = RopUtils.signString(form, "qwertyuiop");
        form.put("sign", sing);

        OkGo.post(new ServerConfig().SERVER)
                .params(form)
                .getCall(StringConvert.create(), RxAdapter.<String>create())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(s -> {
                    if (!"".equals(s)) {
                        if (s.contains("errorToken") || "0".equals(s)) {
                            Toast.makeText(StoreAddActivity.this, "访问服务器失败,请稍后重试", Toast.LENGTH_SHORT).show();
                        } else if ("null".equals(s)) {
                            Toast.makeText(StoreAddActivity.this, "暂无数据", Toast.LENGTH_SHORT).show();
                        } else {
                            List<StoreTypeInfo> result = JSON.parseArray(s, StoreTypeInfo.class);
                            listApplyLevel = new ArrayList<String>();
                            for (int i = 0; i < result.size(); i++) {
                                listApplyLevel.add(result.get(i).getName());
                            }
                            // adpater对象
                            ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(StoreAddActivity.this, android.R.layout.simple_spinner_dropdown_item, listApplyLevel);
                            mAdd_applyLevel.setAdapter(arrayAdapter);
                            mAdd_applyLevel.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                                @Override
                                public void onItemSelected(AdapterView<?> parent, View view,
                                                           int position, long id) {
                                    Spinner spinner = (Spinner) parent;
                                    for (int i = 0; i < listApplyLevel.size(); i++) {
                                        if (spinner.getItemAtPosition(position).toString().equals(result.get(i).getName())) {
//                                             applyLevel = result.get(i).getTextvalue();
                                        }
                                    }
                                }

                                @Override
                                public void onNothingSelected(AdapterView<?> parent) {
                                    Toast.makeText(getApplicationContext(), "没有改变的处理",
                                            Toast.LENGTH_LONG).show();
                                }
                            });
                        }
                    }
                }, throwable -> {
                    showError();
                    throwable.printStackTrace();
                });
    }

    //获取店铺类型
    private void attemptGetStoreTypeTask() {
        Map<String, String> form = Maps.newHashMap();
        form.put("method", "rop.dictionnary.get");
        form.put("appKey", "00001");
        form.put("v", "1.0");
        form.put("format", "json");
        form.put("Parentid", "212");
        String sing = RopUtils.signString(form, "qwertyuiop");
        form.put("sign", sing);

        OkGo.post(new ServerConfig().SERVER)
                .params(form)
                .getCall(StringConvert.create(), RxAdapter.<String>create())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(s -> {
                    if (!"".equals(s)) {
                        if (s.contains("errorToken") || "0".equals(s)) {
                            Toast.makeText(StoreAddActivity.this, "访问服务器失败,请稍后重试", Toast.LENGTH_SHORT).show();
                        } else if ("null".equals(s)) {
                            Toast.makeText(StoreAddActivity.this, "暂无数据", Toast.LENGTH_SHORT).show();
                        } else {
                            List<StoreTypeInfo> result = JSON.parseArray(s, StoreTypeInfo.class);
                            listType = new ArrayList<String>();
                            for (int i = 0; i < result.size(); i++) {
                                listType.add(result.get(i).getName());
                            }
                            // adpater对象
                            final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(StoreAddActivity.this, android.R.layout.simple_spinner_dropdown_item, listType);
                            mAdd_storeType.setAdapter(arrayAdapter);
                            mAdd_storeType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                                @Override
                                public void onItemSelected(AdapterView<?> parent, View view,
                                                           int position, long id) {
                                    Spinner spinner = (Spinner) parent;
                                    for (int i = 0; i < result.size(); i++) {
                                        if (spinner.getItemAtPosition(position).toString().equals(result.get(i).getName())) {
                                            mStoreType = result.get(i).getTextvalue();
                                        }
                                    }
                                }

                                @Override
                                public void onNothingSelected(AdapterView<?> parent) {
                                    Toast.makeText(getApplicationContext(), "没有改变的处理",
                                            Toast.LENGTH_LONG).show();
                                }
                            });
                        }
                    }
                }, throwable -> {
                    showError();
                    throwable.printStackTrace();
                });
    }

    //获取默认的选项
    private void attemptQueryByCusNoMoRen() {
        if ("".equals(mAdd_marketManagerNo.getText().toString().trim())) {
            Toast.makeText(StoreAddActivity.this, "管理人编号不能为空", Toast.LENGTH_SHORT).show();
        } else {
            region = "1";
            mAdd_marketNo.setText("");
            mAdd_marketNo.setEnabled(false);
            customerNo = mAdd_marketManagerNo.getText().toString().trim();

            getDefaultTask(customerNo, region);


            attemptGetCustomerMarket();
            mRadioMoren.setChecked(true);
            mRadioDiy.setVisibility(View.VISIBLE);
            mAdd_ChoiseMarketText.setVisibility(View.VISIBLE);
            mAdd_choiceMarket.setVisibility(View.VISIBLE);
            mRadioDiy.setVisibility(View.INVISIBLE);
            mRadioFirst.setVisibility(View.GONE);
            mRadioSecond.setVisibility(View.GONE);
            mValidate.setVisibility(View.GONE);
        }
    }

    public void getDefaultTask(String customerNo, String grade) {
        Map<String, String> form = Maps.newHashMap();
        form.put("method", "rop.customer.getcustomermoren");
        form.put("appKey", "00001");
        form.put("v", "1.0");
        form.put("format", "json");
        form.put("customerno", customerNo);
        form.put("grade", grade);
        form.put("logid", logid);
        String sing = RopUtils.signString(form, "qwertyuiop");
        form.put("sign", sing);

        OkGo.post(new ServerConfig().SERVER)
                .params(form)
                .getCall(StringConvert.create(), RxAdapter.<String>create())
                .doOnSubscribe(() -> showLoading())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(result -> {
                    dismissLoading();

                    if (!"".equals(result)) {
                        if ("null".equals(result)) {
                            Toast.makeText(StoreAddActivity.this, "访问服务器失败,请稍后重试", Toast.LENGTH_SHORT).show();
                            return;
                        } else if (result.contains("errorToken") || "0".equals(result)) {
                            Toast.makeText(getApplicationContext(), "访问服务器失败,请稍后重试", Toast.LENGTH_SHORT).show();
                            return;
                        } else if ("[]".equals(result)) {
                            mAdd_marketManagerNo.requestFocus();
                            Toast.makeText(StoreAddActivity.this, "不在同一体系", Toast.LENGTH_SHORT).show();
                            return;
                        } else {
                            listAddInfo = JSON.parseArray(result, StoreAddInfo.class);
                            mAdd_marketNo.setText(listAddInfo.get(0).getCustomerno());
                            mAdd_marketNo.setVisibility(View.VISIBLE);
                            if ("自定义".equals(listAddInfo.get(0).getShoptype())) {
                                mRadioDiy.setVisibility(View.VISIBLE);
                                if (!customerNo.equals(listAddInfo.get(0).getCustomerno())) {
                                    listCustomerMarket.add("扶持市场");
                                }
                                //去除重复的值
                                for (int i = 0; i < listCustomerMarket.size() - 1; i++) {
                                    for (int j = listCustomerMarket.size() - 1; j > i; j--) {
                                        if (listCustomerMarket.get(j).equals(listCustomerMarket.get(i))) {
                                            listCustomerMarket.remove(j);
                                        }
                                    }
                                }
                            }
                            mCreateQR.setVisibility(View.VISIBLE);
                            mAddBehalf.setVisibility(View.VISIBLE);
                        }
                    }

                }, throwable -> {
                    dismissLoading();
                    showError();
                    throwable.printStackTrace();
                });
    }

    //获取自定义的选项
    private void attemptQueryByCusNoDIY() {
        if ("".equals(mAdd_marketManagerNo.getText().toString().trim())) {
            Toast.makeText(StoreAddActivity.this, "管理人编号不能为空", Toast.LENGTH_SHORT).show();
        } else {
            customerNo = mAdd_marketManagerNo.getText().toString().trim();
            mRadioDiy.setVisibility(View.VISIBLE);
            mAdd_ChoiseMarketText.setVisibility(View.VISIBLE);
            mAdd_choiceMarket.setVisibility(View.VISIBLE);
            mAdd_marketNo.setVisibility(View.VISIBLE);
            mCreateQR.setVisibility(View.GONE);
            mAddBehalf.setVisibility(View.GONE);
            mValidate.setVisibility(View.VISIBLE);
            mAdd_marketNo.setText("");
            mAdd_marketNo.setEnabled(true);
//            mAdd_choiceMarket.setEnabled(false);
        }
    }

    //获取市场的数据
    private void attemptGetCustomerMarket() {
        listCustomerMarket = new ArrayList();
        listCustomerMarket.add("服务市场");
        ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(StoreAddActivity.this, android.R.layout.simple_spinner_dropdown_item, listCustomerMarket);
        mAdd_choiceMarket.setAdapter(arrayAdapter);
        mAdd_choiceMarket.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view,
                                       int position, long id) {
                final Spinner spinner = (Spinner) parent;
                if ("服务市场".equals(spinner.getItemAtPosition(position).toString())) {
                    region = "1";
                } else {
                    region = "2";
                }
                if (mRadioMoren.isChecked()) {
                    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                        @Override
                        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                            mAdd_marketNo.setText("");
                            customerNo = mAdd_marketManagerNo.getText().toString().trim();
                            if ("服务市场".equals(spinner.getSelectedItem().toString())) {
                                region = "1";
                            } else {
                                region = "2";
                            }
                            if (!mRadioMoren.isChecked()) {
                                mRadioFirst.setVisibility(View.GONE);
                                mRadioSecond.setVisibility(View.GONE);
                                mCreateQR.setVisibility(View.GONE);
                                mAddBehalf.setVisibility(View.GONE);
                                mValidate.setVisibility(View.VISIBLE);
                                return;
                            } else {
                                mCreateQR.setVisibility(View.VISIBLE);
                                mAddBehalf.setVisibility(View.VISIBLE);
                                mValidate.setVisibility(View.GONE);

                                getDefaultTask(customerNo, region);
                            }
                        }

                        @Override
                        public void onNothingSelected(AdapterView<?> parent) {

                        }
                    });
                }
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
                Toast.makeText(getApplicationContext(), "没有改变的处理",
                        Toast.LENGTH_LONG).show();
            }
        });
    }

    //验证信息是否规范
    private void attempValidateDiyTask() {
        mRadioFirst.setChecked(true);
        mRadioSecond.setChecked(false);
        if (mRadioFirst.isChecked()) {
            marketBottom = "1";
        } else if (mRadioSecond.isChecked()) {
            marketBottom = "2";
        }
        String marketno = mAdd_marketNo.getText().toString().trim();
        customerNo = mAdd_marketManagerNo.getText().toString().trim();
        if (customerNo.equals(marketno)) {
            Toast.makeText(StoreAddActivity.this, "编号不能相同", Toast.LENGTH_SHORT).show();
            return;
        }
        mValidate.setVisibility(View.GONE);
        mCreateQR.setVisibility(View.VISIBLE);
        mAddBehalf.setVisibility(View.VISIBLE);

        Map<String, String> form = Maps.newHashMap();
        form.put("method", "rop.customer.getcustomerzixuan");
        form.put("appKey", "00001");
        form.put("v", "1.0");
        form.put("format", "json");
        form.put("Customerno", customerNo);
        form.put("Username", marketno);
        form.put("Qq", region);
        String sing = RopUtils.signString(form, "qwertyuiop");
        form.put("sign", sing);

        OkGo.post(new ServerConfig().SERVER)
                .params(form)
                .getCall(StringConvert.create(), RxAdapter.<String>create())
                .doOnSubscribe(() -> {
                    showLoading();
                })
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(result -> {
                    dismissLoading();
                    if (!"".equals(result)) {
                        switch (result) {
                            case "[]":
                                Toast.makeText(StoreAddActivity.this, "您输入的编号错误,请重新输入!", Toast.LENGTH_SHORT).show();
                                mCreateQR.setVisibility(View.GONE);
                                mAddBehalf.setVisibility(View.GONE);
                                mValidate.setVisibility(View.VISIBLE);
                                break;
                            case "4":
                                mRadioFirst.setVisibility(View.GONE);
                                mRadioSecond.setVisibility(View.GONE);
                                Toast.makeText(StoreAddActivity.this, "不在同一体系,请重新输入!", Toast.LENGTH_SHORT).show();
                                mCreateQR.setVisibility(View.GONE);
                                mAddBehalf.setVisibility(View.GONE);
                                mValidate.setVisibility(View.VISIBLE);
                                break;
                            case "0":
                                if (mRadioMoren.isChecked()) {

                                } else {
                                    mRadioFirst.setVisibility(View.VISIBLE);
                                    mRadioSecond.setVisibility(View.VISIBLE);
                                }
                                break;
                            case "1":
                                mRadioFirst.setVisibility(View.GONE);
                                mRadioSecond.setVisibility(View.VISIBLE);
                                break;
                            case "2":
                                mRadioFirst.setVisibility(View.VISIBLE);
                                mRadioSecond.setVisibility(View.GONE);
                                break;
                            case "3":
                                Toast.makeText(StoreAddActivity.this, "市场名额已满,无法选择!", Toast.LENGTH_SHORT).show();
                                mCreateQR.setVisibility(View.GONE);
                                mAddBehalf.setVisibility(View.GONE);
                                mValidate.setVisibility(View.VISIBLE);
                                break;
                            default:
                                Toast.makeText(StoreAddActivity.this, "不在同一体系,请重新输入!", Toast.LENGTH_SHORT).show();
                                mCreateQR.setVisibility(View.GONE);
                                mAddBehalf.setVisibility(View.GONE);
                                mValidate.setVisibility(View.VISIBLE);
                                break;
                        }
                    }
                }, throwable -> {
                    dismissLoading();
                    showError();
                    throwable.printStackTrace();
                });
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    @Override
    protected void onResume() {
        super.onResume();
        mCreateQR.setVisibility(View.GONE);
        mAddBehalf.setVisibility(View.GONE);
        mValidate.setVisibility(View.GONE);
        mRadioDiy.setVisibility(View.INVISIBLE);
        mRadioFirst.setVisibility(View.INVISIBLE);
        mRadioSecond.setVisibility(View.INVISIBLE);
        mAdd_choiceMarket.setVisibility(View.INVISIBLE);
        mAdd_marketNo.setVisibility(View.INVISIBLE);
        mAdd_ChoiseMarketText.setVisibility(View.INVISIBLE);
    }
}
